# include<stdio.h>
#define N  21252
int main(){
	int p,e,i,d,caseNo=0;
	while(p!=-1&&scanf("%d %d %d %d",&p,&e,&i,&d)){
		caseNo++;
		int k;
		for(k=d+1;(k-p)%23;k++);
			for(;(k-e)%28;k+=23);
				for(;(k-i)%33;k+=23*28);
					printf("%d:the next triple peak occurs in %d",caseNo,k-d);
		}
		return 0;
	}
	
